﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace WCFServiceWebRole1
{
    public class Service1 : IService1
    {
        public string SaveData(string value)
        {
            //Add your connectionString here
            string connectionString = "";
            SqlConnection conn = new SqlConnection(connectionString);

            try
            {
                conn.Open();

                PersonObj person = JsonConvert.DeserializeObject<PersonObj>(value);

                SqlCommand comm = new SqlCommand("INSERT INTO interest VALUES ('" + person.PersonName + "', '" + person.PersonCompany + "', '" + person.PersonDesignation + "', '" + person.PersonEmail + "', '" + person.PersonCell + "'," + person.Win8 + ", " + person.WP + ")", conn);

                return comm.ExecuteNonQuery() + " data entered";
            }
            catch (Exception e)
            {
                return "cannot open database";
            }
        }


    }
    public class PersonObj
    {
        public string PersonName { get; set; }
        public string PersonCompany { get; set; }
        public string PersonDesignation { get; set; }
        public string PersonEmail { get; set; }
        public string PersonCell { get; set; }
        public int Win8 { get; set; }
        public int WP { get; set; }
    }
}
